<include file="Public/header"/>
<include file="Public/menu"/>

<!-- 内容页 -->
<div class="content-wrapper">
    <!-- 面包屑 -->
    <section class="content-header">
        <h1>
            活动专题
            <small>管理</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="{:U('index/index')}"><i class="fa fa-dashboard"></i> 活动专题</a></li>
            <li><a href="{:U('special/cart')}"><i class="fa fa-dashboard"></i> 分类列表</a></li>
            <li class="active">编辑</li>
        </ol>
    </section>

    <!-- 内容 -->
    <section class="content">

        <div class="row">
            <div class="col-md-12">
                <div class="box box-info">
                    <div class="box-header with-border">
                        <h3 class="box-title">编辑专题分类信息</h3>
                        <div class="box-tools">
                            <div class="btn-group pull-right" style="margin-right: 10px">
                                <a href="{:U('special/cart')}" class="btn btn-sm btn-default"><i class="fa fa-list"></i>&nbsp;列表</a>
                            </div>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form id="form" action="{:U('special/editCart')}" method="post" accept-charset="UTF-8" class="form-horizontal">
                        <input type="hidden" name="type_id" value="{$info.type_id}">
                        <div class="box-body">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">分类名称</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <input name="type_name" value="{$info.type_name}" type="text"
                                               class="form-control" placeholder="输入 分类名称">
                                    </div>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">专题商品</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <button type="button" class="btn btn-default pull-left" id="daterange-btn">
                                            <span>
                                              <i class="fa fa-calendar"></i> 点击添加商品
                                            </span>
                                            <i class="fa fa-caret-down"></i>
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-offset-2 col-sm-6 <?php if(count($list) <= 0) echo 'hide';?>">
                                    <div class="box box-primary" style="width:550px;">
                                        <!-- /.box-header -->
                                        <div class="box-body">
                                            <ul class="todo-list ui-sortable edit-batch-list">
                                                <volist name="list" id="vo">
                                                <li>
                                                  <input type="hidden" name="store_pid[]" value="{$vo.store_pid}">
                                                    <a href="javascript:;" class="text ebatch-name" title="{$vo.name}">{$vo.name}</a>
                                                    <small class="label label-warning"> 售价 : {$vo.price}</small>
                                                    <small class="label label-success"> 库存 : {$vo.store}</small>
                                                    <div class="tools">
                                                        <i class="fa fa-trash-o icondel" data-id="{$vo.store_pid}" onclick="deleteProduct(this)"></i>
                                                    </div>
                                                </li>
                                                </volist>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">&nbsp;&nbsp;</label>
                                <div class="col-sm-6">
                                    <div class="no-margin">
                                        <input id="yc-goods-ids" name="product_ids" value="{$s_pids}" type="hidden"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <!-- /.box-body -->
                        <div class="box-footer">
                            <input type="hidden" name="_token" value="7lMdsZohP4DDH6f9Pvt6gn9e8TR3yOc34ovag8h3">
                            <div class="col-sm-2">

                            </div>
                            <div class="col-sm-6">

                                <div class="btn-group pull-right">
                                    <button type="submit" class="btn btn-info pull-right">提交</button>
                                </div>

                            </div>

                        </div>
                        <!-- /.box-footer -->
                    </form>
                </div>

            </div>
        </div>

    </section>
</div>
<!-- 底部 -->

<include file="Public/common_footer"/>
<script src="/Public/layer/layer.js"></script>
<script type="text/javascript">
    $('#daterange-btn').click(function () {
        layer.open({
            type: 2,
            title: '店铺商品库',
            area: ['1400px', '830px'],
            fixed: false,
            maxmin: true,
            content: "{:U('special/getProducts',array('type_id'=>$info['type_id'],''))}"
        });

    });

	var ychser = new YcChoser();
    var chids = $("#yc-goods-ids").val();
    ychser.setChosenIds(chids);

    function deleteProduct(o) {
		ychser.isRepeat($(o).attr("data-id"));
        ychser.remove();
		updateGoodsIds(ychser.getChosenIds());
		$(o).parents("li").remove();
    }
    function updateGoodsIds(ids) {
        $("#yc-goods-ids").val(ids);
        ychser.setChosenIds(ids);
    }

    $('#form').validate({
		ignore: "",
        rules: {
            type_name: {
                required: true,
                rangelength :[2,50]
            },
			product_ids:{
				required: true
			}
        },
        messages: {
            type_name: {
                required: '请输入分类名称'
            },
			product_ids:{
				required: '请至少添加一个专题商品'
			}
        }
    })
</script>
